
//
//  ZTNavigationController.m
//  ZTTaxSecond
//
//  Created by Zhengtong on 15/11/25.
//  Copyright © 2015年 Zhengtong. All rights reserved.
//

#import "ZTNavigationController.h"

@interface ZTNavigationController ()<UINavigationControllerDelegate>

@property (nonatomic, strong) id popDelegate;

@end

@implementation ZTNavigationController


+ (void)initialize
{
    // 获取当前类下面的UIBarButtonItem
    UIBarButtonItem *item = [UIBarButtonItem appearanceWhenContainedIn:self, nil];
    
    // 设置导航条按钮的文字颜色
    //导航标题颜色
    [item setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateNormal];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
   
    [self.navigationBar setBackgroundImage:[UIImage imageNamed:@"上栏"] forBarMetrics:UIBarMetricsDefault];
    self.automaticallyAdjustsScrollViewInsets = YES;
     self.navigationBar.translucent = NO;
    [self.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
    _popDelegate = self.interactivePopGestureRecognizer.delegate;
    self.delegate = self;
    UIBarButtonItem *backBtnItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageWithOriginalName:@"返回按钮.png"] style:UIBarButtonItemStylePlain target:self action:@selector(popToPre)];
    self.navigationItem.leftBarButtonItem = backBtnItem;
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.childViewControllers.count) { // 不是根控制器
        viewController.hidesBottomBarWhenPushed = YES;
        
        UIBarButtonItem *backBtnItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageWithOriginalName:@"返回按钮.png"] style:UIBarButtonItemStylePlain target:self action:@selector(popToPre)];
        self.navigationItem.leftBarButtonItem = backBtnItem;
    }
    [super pushViewController:viewController animated:animated];
    
}
- (void)popToPre
{    [self popViewControllerAnimated:YES];
}
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (viewController == self.viewControllers[0]) { // 是根控制器
        
        self.interactivePopGestureRecognizer.delegate = nil;
        
    }else{ // 非根控制器
        self.interactivePopGestureRecognizer.delegate = _popDelegate;
        
    }
}



@end
